﻿/* 
 * Copyright (c) 2011 Jeff Zhang
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of 
 * this software and associated documentation files (the "Software"), 
 * to deal in the Software without restriction, including without limitation the rights to use, 
 * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 
 * and to permit persons to whom the Software is furnished to do so, 
 * subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included 
 * in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

using System;

namespace Cipher.Compiler.Chm {
    public class Window {
        public string Name { get; private set; }

        public string Title { get; private set; }

        public string TocFile { get; private set; }

        public string IndexFile { get; private set; }

        public string DefaultPage { get; private set; }

        public string HomePage { get; private set; }

        public string Jump1Text { get; private set; }

        public string Jump1Page { get; private set; }

        public string Jump2Text { get; private set; }

        public string Jump2Page { get; private set; }

        public ButtonStyle ToolStyles { get; private set; }

        public TabType DefaultTab { get; private set; }

        public int NavigationPaneWidth { get; private set; }

        public Rect Rectange { get; private set; }

        /// <summary>
        /// 用关闭导航窗格方式打开
        /// </summary>
        public bool OpenWithPaneClosed { get; private set; }

        /// <summary>
        /// The style of navigation.
        /// </summary>
        public NavigationStyle NavStyle { get; private set; }

        public WindowStyles WinStyles { get; private set; }

        public WindowExStyles WinExStyles { get; private set; }

        public override string ToString() {
            return string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19}",
                format(Title),
                format(TocFile),
                format(IndexFile),
                format(DefaultPage),
                format(HomePage),
                format(Jump1Page),
                format(Jump1Text),
                format(Jump2Page),
                format(Jump2Text),
                ((int)NavStyle).ToString("x"),
                NavigationPaneWidth,
                ((int)ToolStyles).ToString("x"),
                Rectange.Left == 0 ? "" : "[" + Rectange.Left + "," + Rectange.Top + "," + Rectange.Width + "," + Rectange.Height + "]",
                ((int)WinStyles).ToString("x"),
                ((int)WinExStyles).ToString("x"),
                "",
                OpenWithPaneClosed ? "1" : "",
                DefaultTab == TabType.None ? "" : ((int)DefaultTab).ToString(),
                "", 
                "0");
        }

        private string format(string text) {
            if (string.IsNullOrEmpty(text))
                return "";

            return "\"" + text + "\"";
        }

        [Flags]
        public enum ButtonStyle {
            HHWIN_BUTTON_EXPAND         = 0x000002, // (1 << 1), // Expand/contract button
            HHWIN_BUTTON_BACK           = 0x000004, // (1 << 2), // Back button
            HHWIN_BUTTON_FORWARD        = 0x000008, // (1 << 3), // Forward button
            HHWIN_BUTTON_STOP           = 0x000010, // (1 << 4), // Stop button
            HHWIN_BUTTON_REFRESH        = 0x000020, // (1 << 5), // Refresh button
            HHWIN_BUTTON_HOME           = 0x000040, // (1 << 6), // Home button
            HHWIN_BUTTON_BROWSE_FWD     = 0x000080, // (1 << 7), // not implemented
            HHWIN_BUTTON_BROWSE_BCK     = 0x000100, // (1 << 8), // not implemented
            HHWIN_BUTTON_NOTES          = 0x000200, // (1 << 9), // not implemented
            HHWIN_BUTTON_CONTENTS       = 0x000400, // (1 << 10), // not implemented
            HHWIN_BUTTON_SYNC           = 0x000800, // (1 << 11), // Sync(address) button
            HHWIN_BUTTON_OPTIONS        = 0x001000, // (1 << 12), // Options button
            HHWIN_BUTTON_PRINT          = 0x002000, // (1 << 13), // Print button
            HHWIN_BUTTON_INDEX          = 0x004000, // (1 << 14), // not implemented
            HHWIN_BUTTON_SEARCH         = 0x008000, // (1 << 15), // not implemented
            HHWIN_BUTTON_HISTORY        = 0x010000, // (1 << 16), // not implemented
            HHWIN_BUTTON_FAVORITES      = 0x020000, // (1 << 17), // not implemented
            HHWIN_BUTTON_JUMP1          = 0x040000, // (1 << 18),
            HHWIN_BUTTON_JUMP2          = 0x080000, // (1 << 19),
            HHWIN_BUTTON_ZOOM           = 0x100000, // (1 << 20),
            HHWIN_BUTTON_TOC_NEXT       = 0x200000, // (1 << 21),
            HHWIN_BUTTON_TOC_PREV       = 0x400000, // (1 << 22),
        }

        public struct Rect {
            public int Left;
            public int Top;
            public int Width;
            public int Height;
        }

        public enum TabType {
            None = -1,
            Toc,
            Index,
            Search,
            Favorites,
            // not implemented
            History,
            Author,
            CustomeFirst = 11
        }

        [Flags]
        public enum NavigationStyle {
            /// <summary>
            /// (1 << 0)
            /// Automatically hide/show tri-pane window
            /// 导航窗格->自动显示/隐藏导航窗格
            /// </summary>
            HHWIN_PROP_TAB_AUTOHIDESHOW = 0x00000001, 
            HHWIN_PROP_ONTOP            = 0x00000002, //(1 << 1),    // Top-most window
            HHWIN_PROP_NOTITLEBAR       = 0x00000004, //(1 << 2),    // no title bar
            HHWIN_PROP_NODEF_STYLES     = 0x00000008, //(1 << 3),    // no default window styles =(only HH_WINTYPE.dwStyles),
            HHWIN_PROP_NODEF_EXSTYLES   = 0x00000010, //(1 << 4),    // no default extended window styles =(only HH_WINTYPE.dwExStyles),
            /// <summary>
            /// use a tri-pane window
            /// 导航窗格->窗口带有导航窗格，主题窗格，和按钮栏
            /// </summary>
            HHWIN_PROP_TRI_PANE         = 0x00000020, // (1 << 5),    
            HHWIN_PROP_NOTB_TEXT        = 0x00000040, //(1 << 6),    // no text on toolbar buttons
            HHWIN_PROP_POST_QUIT        = 0x00000080, //(1 << 7),    // post WM_QUIT message when window closes

            /// <summary>
            /// (1 << 8)    
            /// automatically ssync contents and index
            /// 导航窗格->自动同步
            /// </summary>
            HHWIN_PROP_AUTO_SYNC        = 0x00000100, 
            HHWIN_PROP_TRACKING         = 0x00000200, //(1 << 9),    // send tracking notification messages

            /// <summary>
            /// (1 << 10)
            /// include search tab in navigation pane
            /// 导航窗格->搜索标签
            /// </summary>
            HHWIN_PROP_TAB_SEARCH       = 0x00000400,
            HHWIN_PROP_TAB_HISTORY      = 0x00000800, //(1 << 11),   // include history tab in navigation pane

            /// <summary>
            /// (1 << 12)
            /// include favorites tab in navigation pane
            /// 导航窗格->收藏夹标签
            /// </summary>
            HHWIN_PROP_TAB_FAVORITES    = 0x00001000,
            HHWIN_PROP_CHANGE_TITLE     = 0x00002000, //(1 << 13),   // Put current HTML title in title bar
            HHWIN_PROP_NAV_ONLY_WIN     = 0x00004000, //(1 << 14),   // Only display the navigation window
            HHWIN_PROP_NO_TOOLBAR       = 0x00008000, //(1 << 15),   // Don't display a toolbar
            HHWIN_PROP_MENU             = 0x00010000, //(1 << 16),   // Menu

            /// <summary>
            /// (1 << 17)
            /// Advanced FTS UI.
            /// 导航窗格->高级搜索
            /// </summary>
            HHWIN_PROP_TAB_ADVSEARCH    = 0x00020000,

            /// <summary>
            /// (1 << 18)
            /// After initial creation, user controls window size/position
            /// 位置->第一次使用后保存用户自定义的窗口位置
            /// </summary>
            HHWIN_PROP_USER_POS         = 0x00040000,
            HHWIN_PROP_TAB_CUSTOM1      = 0x00080000, //(1 << 19),   // Use custom tab #1
            HHWIN_PROP_TAB_CUSTOM2      = 0x00100000, //(1 << 20),   // Use custom tab #2
            HHWIN_PROP_TAB_CUSTOM3      = 0x00200000, //(1 << 21),   // Use custom tab #3
            HHWIN_PROP_TAB_CUSTOM4      = 0x00400000, //(1 << 22),   // Use custom tab #4
            HHWIN_PROP_TAB_CUSTOM5      = 0x00800000, //(1 << 23),   // Use custom tab #5
            HHWIN_PROP_TAB_CUSTOM6      = 0x01000000, //(1 << 24),   // Use custom tab #6
            HHWIN_PROP_TAB_CUSTOM7      = 0x02000000, //(1 << 25),   // Use custom tab #7
            HHWIN_PROP_TAB_CUSTOM8      = 0x04000000, //(1 << 26),   // Use custom tab #8
            HHWIN_PROP_TAB_CUSTOM9      = 0x08000000, //(1 << 27),   // Use custom tab #9
            HHWIN_TB_MARGIN             = 0x10000000, //(1 << 28),   // the window type has a margin
        }

        /// <summary>
        /// Styles
        /// </summary>
        [Flags]
        public enum WindowStyles : uint {
            /// <summary>
            /// Overlapped
            /// </summary>
            WS_OVERLAPPED = 0x00000000,

            /// <summary>
            /// Pop-up
            /// </summary>
            WS_POPUP = 0x80000000,

            /// <summary>
            /// Minimize
            /// </summary>
            WS_MINIMIZE = 0x20000000,

            /// <summary>
            /// Visible
            /// </summary>
            WS_VISIBLE = 0x10000000,

            /// <summary>
            /// Disabled
            /// </summary>
            WS_DISABLED = 0x08000000,

            /// <summary>
            /// Clip sibling windows
            /// </summary>
            WS_CLIPSIBLINGS = 0x04000000,

            /// <summary>
            /// Clip child windows
            /// </summary>
            WS_CLIPCHILDREN = 0x02000000,

            /// <summary>
            /// Maximize
            /// </summary>
            WS_MAXIMIZE = 0x01000000,

            /// <summary>
            /// Border
            /// </summary>
            WS_BORDER = 0x00800000,

            /// <summary>
            /// Dlg frame
            /// </summary>
            WS_DLGFRAME = 0x00400000,

            /// <summary>
            /// Vertical scroll
            /// </summary>
            WS_VSCROLL = 0x00200000,

            /// <summary>
            /// Horizontal scroll
            /// </summary>
            WS_HSCROLL = 0x00100000,

            /// <summary>
            /// System menu
            /// </summary>
            WS_SYSMENU = 0x00080000,

            /// <summary>
            /// Thick frame
            /// </summary>
            WS_THICKFRAME = 0x00040000,

            /// <summary>
            /// Minimize box
            /// </summary>
            WS_MINIMIZEBOX = 0x00020000,

            /// <summary>
            /// Maximize box
            /// </summary>
            WS_MAXIMIZEBOX = 0x00010000,

            #region not used
            /*
            WS_CAPTION = 0x00C00000,
            WS_GROUP = 0x00020000,
            WS_CHILD = 0x40000000,
            WS_TABSTOP = 0x00010000,
            WS_TILED = WS_OVERLAPPED,
            WS_ICONIC = WS_MINIMIZE,
            WS_SIZEBOX = WS_THICKFRAME,
            WS_TILEDWINDOW = WS_OVERLAPPEDWINDOW,
            WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION |
                WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
            WS_POPUPWINDOW = WS_POPUP | WS_BORDER | WS_SYSMENU,
            WS_CHILDWINDOW = WS_CHILD,
             * */
            #endregion
        };


        /// <summary>
        /// Extended styles
        /// </summary>
        [Flags]
        public enum WindowExStyles : uint {
            /// <summary>
            /// No parent notify
            /// </summary>
            WS_EX_NOPARENTNOTIFY = 0x00000004,
            
            /// <summary>
            /// Topmost
            /// </summary>
            WS_EX_TOPMOST = 0x00000008,

            /// <summary>
            /// Accept files
            /// </summary>
            WS_EX_ACCEPTFILES = 0x00000010,

            /// <summary>
            /// Transparent
            /// </summary>
            WS_EX_TRANSPARENT = 0x00000020,
            
            /// <summary>
            /// Tool window  
            /// </summary>
            WS_EX_TOOLWINDOW = 0x00000080,

            /// <summary>
            /// Client edge
            /// </summary>
            WS_EX_CLIENTEDGE = 0x00000200,

            /// <summary>
            /// Context help
            /// </summary>
            WS_EX_CONTEXTHELP = 0x00000400,

            /// <summary>
            /// Right-aligned text
            /// </summary>
            WS_EX_RIGHT = 0x00001000,

            /// <summary>
            /// Right-to-left reading order
            /// </summary>
            WS_EX_RTLREADING = 0x00002000,

            /// <summary>
            /// Left scroll bar
            /// </summary>
            WS_EX_LEFTSCROLLBAR = 0x00004000,

            /// <summary>
            /// Control parent window
            /// </summary>
            WS_EX_CONTROLPARENT = 0x00010000,

            /// <summary>
            /// Static edge
            /// </summary>
            WS_EX_STATICEDGE = 0x00020000,

            #region not used

            /*
            WS_EX_DLGMODALFRAME = 0x00000001,
            WS_EX_MDICHILD = 0x00000040,
            WS_EX_WINDOWEDGE = 0x00000100,
            WS_EX_LEFT = 0x00000000,
            WS_EX_LTRREADING = 0x00000000,
            WS_EX_RIGHTSCROLLBAR = 0x00000000,
            WS_EX_APPWINDOW = 0x00040000,
            WS_EX_OVERLAPPEDWINDOW = WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE,
            WS_EX_PALETTEWINDOW = WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST,
            WS_EX_LAYERED = 0x00080000,
            WS_EX_NOINHERITLAYOUT = 0x00100000,
            WS_EX_LAYOUTRTL = 0x00400000,
            WS_EX_COMPOSITED = 0x02000000,
            WS_EX_NOACTIVATE = 0x08000000
             * */
            #endregion
        };
    }
}
